using System.Collections.Generic;

namespace OracleInternal.SqlAndPlsqlParser.RuleProcessors
{
	internal class OracleMbParserContextBase<T, U> where T : Parser
	{
		protected readonly Dictionary<string, U> m_vRuleProcessorTableDictionary;

		protected readonly T m_vParser;

		protected string m_vScriptText;

		protected List<LexerToken> m_vTokens;

		protected ParseNode m_vRootParseNode;

		protected ParseNode m_vCurrentParseNode;

		protected int m_vCurrentRuleIndex;

		protected U m_vRuleProcessorTable;

		protected List<string> m_vActiveViewColumnAliases;

		protected OracleMbParserPropertiesBag m_vPropertiesBag = new OracleMbParserPropertiesBag();

		public T Parser => m_vParser;

		public string Script
		{
			get
			{
				return m_vScriptText;
			}
			set
			{
				m_vScriptText = value;
			}
		}

		public List<LexerToken> Tokens
		{
			get
			{
				return m_vTokens;
			}
			set
			{
				m_vTokens = value;
			}
		}

		public ParseNode RootParseNode
		{
			get
			{
				return m_vRootParseNode;
			}
			set
			{
				m_vRootParseNode = value;
			}
		}

		public ParseNode CurrentParseNode
		{
			get
			{
				return m_vCurrentParseNode;
			}
			set
			{
				m_vCurrentParseNode = value;
			}
		}

		public int CurrentRuleIndex
		{
			get
			{
				return m_vCurrentRuleIndex;
			}
			set
			{
				m_vCurrentRuleIndex = value;
			}
		}

		public U RuleProcessorTable
		{
			get
			{
				return m_vRuleProcessorTable;
			}
			set
			{
				m_vRuleProcessorTable = value;
			}
		}

		public List<string> ActiveViewColumnAliases
		{
			get
			{
				return m_vActiveViewColumnAliases;
			}
			set
			{
				m_vActiveViewColumnAliases = value;
			}
		}

		public OracleMbParserPropertiesBag PropertiesBag => m_vPropertiesBag;

		public OracleMbParserContextBase(T parser, OracleMbRuleProcessorTableDictionary<U> ruleProcessorTableDictionary)
		{
			m_vParser = parser;
			m_vRuleProcessorTableDictionary = ruleProcessorTableDictionary.RuleProcessorTableDictionary;
			m_vRuleProcessorTable = GetRuleProcessorTable("ODPCommands");
		}

		public string GetStatementBetweenGivenSrcAndTgtTokenIdx(int srcTokenIdx, int tgtTokenIdx)
		{
			if (srcTokenIdx < 0 || tgtTokenIdx < 0 || srcTokenIdx > tgtTokenIdx)
			{
				return string.Empty;
			}
			int vBegin = Tokens[srcTokenIdx].m_vBegin;
			int length = Tokens[tgtTokenIdx].m_vEnd - vBegin;
			return Script.Substring(vBegin, length);
		}

		public U GetRuleProcessorTable(string name)
		{
			if (!m_vRuleProcessorTableDictionary.TryGetValue(name, out var value))
			{
				return m_vRuleProcessorTableDictionary["empty"];
			}
			return value;
		}

		public virtual void Clear()
		{
			m_vPropertiesBag.Clear();
			m_vCurrentRuleIndex = 0;
			m_vCurrentParseNode = null;
			m_vRootParseNode = null;
			m_vTokens = null;
			m_vScriptText = null;
		}
	}
}
